#include <iostream>
extern "C"{
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
#include <libavutil/imgutils.h>
}
int is_h264_file(char *filename)
{
    AVFormatContext *ifmt_ctx = NULL;
    int ret = 0;
    
    
    if ((ret = avformat_open_input(&ifmt_ctx, filename, 0, 0)) < 0) {
        
        printf( "Could not open input file.");
        
        return 0;
        
    }
    //	printf("1ifmt_ctx->video_codec_id:%d\n",ifmt_ctx->video_codec_id);
    if ((ret = avformat_find_stream_info(ifmt_ctx, 0)) < 0) {
        
        printf( "Failed to retrieve input stream information");
        
        avformat_close_input(&ifmt_ctx);
        return 0;
        
    }
    
    //ifmt_ctx->streams[0]->codecpar->codec_id;
    
    printf("3ifmt_ctx->video_codec_id:%d\n",ifmt_ctx->streams[0]->codecpar->codec_id);
    
    
    if(ifmt_ctx->streams[0]->codecpar->codec_id==AV_CODEC_ID_H264)
    {
        printf("is h264 file\n");
        avformat_close_input(&ifmt_ctx);
        return 1;
    }
    
    else
    {
        printf("is not h264 file\n");
        avformat_close_input(&ifmt_ctx);
        return 0;
    }
    
}



int main(int argc, char* argv[])

{
    char * filepath="D:\\KuGou\\Sing\\伍佰 - 爱你一万年.flac";
    is_h264_file(filepath);
}
